package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportManageRoleRel;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportManageRoleRelDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-01-28 11:16:34
 */
public class TransportManageRoleRelConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportManageRoleRelConverts.class);

    public static List<TransportManageRoleRelDTO> convert(List<TransportManageRoleRel> transportManageRoleRelList) {
        if (CollectionUtils.isEmpty(transportManageRoleRelList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportManageRoleRelDTO> transportManageRoleRelListResult = Lists.newArrayList();
        for (TransportManageRoleRel transportManageRoleRel : transportManageRoleRelList) {
            transportManageRoleRelListResult.add(convert(transportManageRoleRel));
        }
        return transportManageRoleRelListResult;
    }

    public static TransportManageRoleRelDTO convert(TransportManageRoleRel transportManageRoleRel) {
        try {
            return BeanUtils.copy(transportManageRoleRel, TransportManageRoleRelDTO.class);
        } catch (Exception e) {
            LOG.error("TransportManageRoleRel到TransportManageRoleRelDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportManageRoleRel到TransportManageRoleRelDTO转换失败", e);
        }
    }

    public static TransportManageRoleRel convert(TransportManageRoleRelDTO transportManageRoleRelDTO) {
        try {
            return BeanUtils.copy(transportManageRoleRelDTO, TransportManageRoleRel.class);
        } catch (Exception e) {
            LOG.error("TransportManageRoleRelDTO到TransportManageRoleRel转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportManageRoleRelDTO到TransportManageRoleRel转换失败", e);
        }
    }
}